#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

vector<int> dp;
int pick_total = 0;

void fun(const vector<int> &coins, int target, bool &stop)
{
    if(target == 0){
        for(auto i: dp){
            cout << i << " ";
        }
        cout << endl;
        stop = true;
    }
    for(int i{}; i < coins.size(); i++){
        if(stop) return;
        if(coins[i] <= target){
            pick_total += coins[i];
            dp.push_back(coins[i]);
            fun(coins, target - coins[i], stop);
            dp.pop_back();
            pick_total -= coins[i];
        }
    }
    
}

int main(int args, char *argv[])
{
    bool stop = false;
    fun({5, 3, 1}, 103, stop);

    return 0;
}